<?php
$this->placeholder('title')->set('');
?>


<?php
$this->posts = array(
    '1' => array(
        'postId' => 'id_1',
        'postTitle' => 'title_1',
        'postDetail' => 'detail_1',
    ),
    '2' => array(
        'postId' => 'id_2',
        'postTitle' => 'title_2',
        'postDetail' => 'detail_2',
    ),
    '3' => array(
        'postId' => 'id_3',
        'postTitle' => 'title_3',
        'postDetail' => 'detail_3',
    ),
    '4' => array(
        'postId' => 'id_4',
        'postTitle' => 'title_4',
        'postDetail' => 'detail_4',
    ),
    '5' => array(
        'postId' => 'id_5',
        'postTitle' => 'title_5',
        'postDetail' => 'detail_5',
    ),
    '6' => array(
        'postId' => 'id_6',
        'postTitle' => 'title_6',
        'postDetail' => 'detail_6',
    ),
);

if (isset($this->posts)) {
    $this->dojo()->enable()
                 ->setCdnVersion('1.3.1')
                 ->setDjConfigOption('parseOnLoad', true)
                 ->setDjConfigOption('isDebug', false)
                 ->setDjConfigOption('locale', 'zh')

                 ->registerDojoStylesheet(true)
                 ->addStylesheet('http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojox/grid/resources/Grid.css')
                 ->addStylesheet('http://ajax.googleapis.com/ajax/libs/dojo/1.3/dojox/grid/resources/tundraGrid.css')
                 ->addStylesheet('http://ajax.googleapis.com/ajax/libs/dojo/1.3/dijit/themes/tundra/tundra.css')

                 ->requireModule('dijit.dijit')
                 ->requireModule('dojox.grid.DataGrid')
                 ->requireModule('dojo.data.ItemFileWriteStore')
                 ->requireModule('dojo.parser')
                 ;

    echo $this->dojo();

    $data = new Zend_Dojo_Data();
    $data->setIdentifier('postId')
         ->setLabel('My post list')
         ->addItems($this->posts);

    //var_dump($data);
?>

    <script type="text/javascript">
        dojo.addOnLoad(function() {
            var gridLayout = [[
                {name: 'Post',      field: 'postId',        width: "50px"},
                {name: 'Title',     field: 'postTitle',     width: "200px"},
                {name: 'Detail',    field: 'postDetail',    width: "400px"}
            ]];

            // For debug
            //console.log('<?php echo $data; ?>');

            var test_store = new dojo.data.ItemFileWriteStore({data: <?php echo $data; ?>});
            gridNode.setStructure(gridLayout);
            gridNode.setStore(test_store);
        });
    </script>

    <div jsId="gridNode" dojoType="dojox.grid.DataGrid" rowsPerPage="10" style="width:675px; height:400px;"></div>
<?php
}
?>